package xyz.yq56.easytool.utils.statistic;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import xyz.yq56.easytool.utils.nvll.NullUtil;

/**
 * @author yi qiang
 * @date 2021/12/25 13:38
 */
public class CountUtil {

    private CountUtil() {
    }

    /**
     * 分组计数
     */
    public static <T, K> Map<K, Long> groupCount(List<T> list, Function<? super T, ? extends K> classifier) {
        return NullUtil.emptyIfNull(list).stream().collect(Collectors.groupingBy(classifier, Collectors.counting()));
    }

}
